package com.itany.corejava.code06_数组;

import java.util.Arrays;

/**
 * @author 石小俊
 * 2024年07月10日 15:15
 */
public class Test04_Arrays工具类 {

    public static void main(String[] args) {
        sortTest();
    }

    public static void toStringTest() {
        int[] nums = {1, 2, 3, 4, 5, 6, 7, 8};
        System.out.println(nums);
        System.out.println(Arrays.toString(nums));

        System.out.print("[");
        for (int i = 0; i < nums.length; i++) {
            if (i != nums.length - 1) {
                System.out.print(nums[i] + ", ");
            } else {
                System.out.print(nums[i]);
            }
        }
        System.out.println("]");
    }


    public static void sortTest() {
        int[] nums = {7, 4, 9, 12, 17, 14, 3, 1};
        // sort:排序
        // 如果是一个数字类型,则按照数值大小进行升序排序
        Arrays.sort(nums);
        System.out.println(Arrays.toString(nums));

        // 如果是一个字符串,则按照字典顺序进行升序排序
        String[] names = {"jack", "alice", "tom", "lucy", "admin"};
        Arrays.sort(names);
        System.out.println(Arrays.toString(names));

        String[] numbers = {"7", "16", "12", "1", "5", "22", "21"};
        Arrays.sort(numbers);
        System.out.println(Arrays.toString(numbers));
    }
}
